package com.atguigu.gmall.product.service.impl;

import com.atguigu.cache.annotate.GmallCache;
import com.atguigu.gmall.common.constant.RedisConstant;
import com.atguigu.gmall.model.product.to.CategoryTO;
import com.atguigu.gmall.model.product.to.CategoryView;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.gmall.model.product.entity.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategory3Service;
import com.atguigu.gmall.product.mapper.BaseCategory3Mapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author jiamin
 * @description 针对表【base_category3(三级分类表)】的数据库操作Service实现
 * @createDate 2023-08-14 20:41:58
 */
@Service
public class BaseCategory3ServiceImpl extends ServiceImpl<BaseCategory3Mapper, BaseCategory3>
        implements BaseCategory3Service {


    @Override
    public List<BaseCategory3> getCategory3(Long category2Id) {
        LambdaQueryWrapper<BaseCategory3> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BaseCategory3::getCategory2Id, category2Id);
        List<BaseCategory3> baseCategory3List = baseMapper.selectList(queryWrapper);
        return baseCategory3List;
    }

    @Override
    @GmallCache(key = RedisConstant.REDIS_CATEGORY_TREE_KEY)
    public List<CategoryTO> getCategory() {
        List<CategoryTO> category = baseMapper.getCategory();
        return category;
    }

    @Override
    public CategoryView getCategoryByC3Id(Long c3Id) {
        return baseMapper.getCategoryByC3Id(c3Id);
    }
}




